﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace MyFirstWpfApp
{
    class MyDepPro : Label
    {
        string text;
        int wid;
        int hei;

        public int Wid
        {
            get
            {
                return wid;
            }
            set
            {
                wid = value;
                this.Width = wid;
            }
        }

        public int Hei
        {
            get
            {
                return hei;
            }
            set
            {
                hei = value;
                this.Height = hei;
            }
        }

        public static readonly DependencyProperty SizeProperty;

        public string Text
        {
            get
            {
                return text;
            }
            set
            {
                text = value;
                this.Content = text;
            }
        }

        public int Size
        {
            get
            {
                return (int)GetValue(SizeProperty);
            }
            set
            {
                SetValue(SizeProperty, value);
            }
        }

        static MyDepPro()
        {
            FrameworkPropertyMetadata metadata = new FrameworkPropertyMetadata();
            metadata.DefaultValue = 1;
            metadata.AffectsMeasure = true;
            metadata.Inherits = true;
            metadata.PropertyChangedCallback += OnSizePropertyChanged;
            SizeProperty = DependencyProperty.Register("Size", typeof(int), typeof(MyDepPro), metadata, SpaceProperty_ValidateValue);
        }

        static void OnSizePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            MyDepPro mdp = obj as MyDepPro;
            mdp.FontSize = mdp.Size;
            mdp.Hei += mdp.Size;
            mdp.Wid += mdp.Size;
        }

        static bool SpaceProperty_ValidateValue(object value)
        {
            int? objAsInt = value as int?;
            if (objAsInt == null)
            {
                return false;
            }

            return ((objAsInt >= 0) && (objAsInt <= 1000));
        }
    }
}
